import rospy
from geometry_msgs.msg import Twist


def move_forward():
    # 初始化ROS节点
    rospy.init_node('move_forward_node')

    # 创建/cmd_vel话题的发布者
    cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)

    # 设置发布速度消息的频率
    rate = rospy.Rate(10)

    # 创建Twist消息并初始化速度
    twist = Twist()
    twist.linear.x = 0.1

    # 发布速度消息，持续1秒
    start_time = rospy.Time.now()
    while rospy.Time.now() - start_time < rospy.Duration(1):
        cmd_vel_pub.publish(twist)
        rate.sleep()

    # 停止机器人运动
    twist.linear.x = 0.0
    cmd_vel_pub.publish(twist)


if __name__ == '__main__':
    try:
        move_forward()
    except rospy.ROSInterruptException:
        pass
